package com.mystring.mapper;

import com.mystring.po.Product;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Component;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * ClassName: ProductMapper
 * Package: com.mystring.mapper
 * Description:
 *
 * @Author 刘英杰
 * @Create 2025/2/6 16:41
 * @Version 1.0
 */

@Component
public class ProductMapper implements RowMapper<Product> {
    @Override
    public Product mapRow(ResultSet resultSet, int i) throws SQLException {
        /**
         * 需要自己去手动将结果列封装成对象
         */
        //1.新建一个封装的对象
        Product product = new Product();
        //2.获取结果列中的值,将这些值设置到对象中
        product.setPid(resultSet.getInt("pid"));
        product.setPname(resultSet.getString("pname"));
        product.setPrice(resultSet.getDouble("price"));
        product.setCategory(resultSet.getString("category"));
        //3.返回这个对象
        return product;
    }
}
